home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************/
- /* */
- /* THE POOP SHELL */
- /* */
- /********************************************************************/
- /* An Adventure in Pseudo-Object-Oriented-Programming */
- /********************************************************************/
- /*
- * >>> File name: EventHandlers
- *
- * >>> Purpose: The main event loop (Twiddle) and other high
- level event handlers
- * >>> Project: Briefcase
- * >>> Date: April 5, 1989
- * >>> By: Adam Treister
- *
- */
- /********************************************************************/
- /* For Your Information 1802 Hillside Rd. SB CA 93101 */
- /********************************************************************/
- #include "PoopDrawInc"
-
- void DoMenuCommand (long MenuSelectResult);
-
- public void Twiddle (void);
- private void DoMouseDown (EventRecord Event);
- private void DoMouseUp (EventRecord Event);
- private Boolean ClickIsInActiveWindow (WindowPtr ClickedWindow);
- private void DoKeyDown (EventRecord Event);
- private void DoUpdate (WindowPtr wP);
- private void DoActivate (EventRecord Event);
- private void DoSuspendResume (void);
-
-
- /* ------------------------------------------------------------ */
- /* */
- /* MAIN EVENT LOOP */
- /* */
- /* */
- /* ------------------------------------------------------------ */
-
- void Twiddle()
- {
- extern EventRecord Event;
- extern Boolean MillerTime;
- register long Sleep = 10;
- register Boolean EventPending;
- register WindowPtr wP;
-
- while (!MillerTime)
- {
-
- EventPending = WaitNextEvent(everyEvent, &Event,Sleep,NULL);
- if (EventPending)
- {
- switch (Event.what)
- {
- case mouseDown: DoMouseDown(Event); break;
- case mouseUp: DoMouseUp(Event); break;
-
- case keyDown:
- case autoKey: DoKeyDown(Event); break;
-
- case updateEvt: DoUpdate((WindowPtr)Event.message); break;
-
- case activateEvt: DoActivate(Event); break;
- }
-
- } /* if EventPending*/
- else
- {
- if (OurWindow(wP = MyFrontWindow())) WDispatch(wP,IDLE,NULL);
-
-
- } } }
-
- Boolean DoubleClicked; /* the last mouse down was a double */
- private long LastMouseUp;
- private Point LastMouseUpLoc; /*not used for now */
-
- /* ------------------------------------------------------------ */
- /* */
- /* DO MOUSE DOWN */
- /* */
- /* This function handles a mouse down event. FindWindow is */
- /* called to find which window the mouse is in. Then the event */
- /* is "Dispatched" there. */
- /* */
- /* ------------------------------------------------------------ */
-
- void DoMouseDown(Event)
- EventRecord Event;
- {
-
- WindowPtr WhichWindow; /* the event window */
- register Point MousePosition; /* the current mouse position */
- register int Where; /* the result of FindWindow */
- Rect DragRect;
- long okay = TRUE;
-
- DoubleClicked = (Event.when - LastMouseUp < GetDblTime());
-
- MousePosition = Event.where;
- Where = FindWindow(MousePosition, &WhichWindow);
-
- switch (Where)
- {
- case inDesk: break;
-
- case inMenuBar: DoMenuCommand(MenuSelect(&Event.where));
- break;
-
- case inSysWindow: SystemClick(&Event, WhichWindow);
- break;
-
- case inContent: if (ClickIsInActiveWindow(WhichWindow))
- WDispatch(WhichWindow,MOUSEDOWN,NULL);
- break;
-
- case inDrag: DragRect = screenBits.bounds;
- DragWindow(WhichWindow,MousePosition, &DragRect);
- break;
-
-
- case inGrow: WDispatch(WhichWindow,GROW,NULL);
- break;
-
- case inGoAway: if (TrackGoAway(WhichWindow, MousePosition))
- if ( _OptionKeyDown(Event))
- while ((WhichWindow = MyFrontWindow()) AND okay)
- { WDispatch(WhichWindow,CLOSE,&okay);}
- else WDispatch(WhichWindow,CLOSE,&okay);
-
- break;
- default:
- Oops("\pUnknown Window Type in MouseDown Handler", 0, TRUE);
- break;
-
- } /* switch (FindWindow..) */
- }
- /* ------------------------------------------------------------ */
- /* DoMouseUp */
- /* */
- /* Set the current time into LastMouseUp for Double Click */
- /* Detection in DoMouseDown. */
- /* */
- /* ------------------------------------------------------------ */
-
- void DoMouseUp(Event)
- EventRecord Event;
- {
- extern long LastMouseUp;
- LastMouseUp = Event.when;
- }
-
- /* ------------------------------------------------------------ */
- /* Boolean ClickIsInActiveWindow(ClickedWindow) */
- /* */
- /* A quickie to select back windows if the're clicked. */
- /* */
- /* ------------------------------------------------------------ */
- #define ItIsnt (!ItIs)
-
- Boolean ClickIsInActiveWindow(ClickedWindow)
- WindowPtr ClickedWindow;
- {
- register Boolean ItIs;
- long type;
-
- ItIs = (ClickedWindow == FrontWindow());
- if (ItIsnt) SelectWindow(ClickedWindow);
- return(ItIs);
- }
-
- /* ------------------------------------------------------------ */
- /* */
- /* DO KEY DOWN */
- /* */
- /* This function handles a keydown event. If the command */
- /* key is down its a menu command, otherwise dispatch it */
- /* */
- /* */
- /* ------------------------------------------------------------ */
-
- void DoKeyDown(Event)
- EventRecord Event;
- {
- register char key;
-
- key = Event.message & charCodeMask;
-
- if (_CmdKeyDown(Event)) DoMenuCommand(MenuKey(key));
- else if (MyFrontWindow()) WDispatch(MyFrontWindow(),KEYDOWN,NULL);
- }
-
- /* ------------------------------------------------------------ */
- /* */
- /* DO UPDATE */
- /* */
- /* ------------------------------------------------------------ */
-
- void DoUpdate(wP)
- register WindowPtr wP;
- {
- GrafPtr PortSave;
-
- GetPort(&PortSave);
- SetPort(wP);
-
- BeginUpdate(wP);
- WDispatch(wP,UPDATE,NULL);
- EndUpdate(wP);
-
- SetPort(PortSave);
- }
-
- /* ------------------------------------------------------------ */
- /* */
- /* DO ACTIVATE */
- /* */
- /* ------------------------------------------------------------ */
-
- void DoActivate(Event)
- EventRecord Event;
- {
- register WindowPtr ActivateWindow;
- register int Message = DEACTIVATE;
-
- TurnArrowOn();
- ActivateWindow = (WindowPtr) Event.message;
-
- if (Event.modifiers & activeFlag) /* Activate vs Deactivate */
- {
- SetPort(ActivateWindow);
- Message = ACTIVATE;
- }
- WDispatch(ActivateWindow,Message,NULL);
- }
-
-